<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="计划id（需要结合计划ID）" prop="scheduleId">
      <el-input v-model="dataForm.scheduleId" placeholder="计划id（需要结合计划ID）"></el-input>
    </el-form-item>
    <el-form-item label="专题id（实际还是以专题为单位）" prop="specialId">
      <el-input v-model="dataForm.specialId" placeholder="专题id（实际还是以专题为单位）"></el-input>
    </el-form-item>
    <el-form-item label="当前电子因子值" prop="currentEf">
      <el-input v-model="dataForm.currentEf" placeholder="当前电子因子值"></el-input>
    </el-form-item>
    <el-form-item label="当前相应质量（5-完美响应/完全掌握；4-犹豫后正确的响应/基本掌握；3-严重困难时召回的正确响应/不太掌握；2-错误的响应；正确的人似乎容易被回忆的地方/完全不会！1-错误的回答；正确的记忆/完全不会！0-完全停电/完全不会！）" prop="currentQuantity">
      <el-input v-model="dataForm.currentQuantity" placeholder="当前相应质量（5-完美响应/完全掌握；4-犹豫后正确的响应/基本掌握；3-严重困难时召回的正确响应/不太掌握；2-错误的响应；正确的人似乎容易被回忆的地方/完全不会！1-错误的回答；正确的记忆/完全不会！0-完全停电/完全不会！）"></el-input>
    </el-form-item>
    <el-form-item label="是否为最近的" prop="islatest">
      <el-input v-model="dataForm.islatest" placeholder="是否为最近的"></el-input>
    </el-form-item>
    <el-form-item label="间隔天数" prop="interval">
      <el-input v-model="dataForm.interval" placeholder="间隔天数"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          scheduleId: '',
          specialId: '',
          currentEf: '',
          currentQuantity: '',
          islatest: '',
          interval: '',
          createTime: ''
        },
        dataRule: {
          scheduleId: [
            { required: true, message: '计划id（需要结合计划ID）不能为空', trigger: 'blur' }
          ],
          specialId: [
            { required: true, message: '专题id（实际还是以专题为单位）不能为空', trigger: 'blur' }
          ],
          currentEf: [
            { required: true, message: '当前电子因子值不能为空', trigger: 'blur' }
          ],
          currentQuantity: [
            { required: true, message: '当前相应质量（5-完美响应/完全掌握；4-犹豫后正确的响应/基本掌握；3-严重困难时召回的正确响应/不太掌握；2-错误的响应；正确的人似乎容易被回忆的地方/完全不会！1-错误的回答；正确的记忆/完全不会！0-完全停电/完全不会！）不能为空', trigger: 'blur' }
          ],
          islatest: [
            { required: true, message: '是否为最近的不能为空', trigger: 'blur' }
          ],
          interval: [
            { required: true, message: '间隔天数不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/avanotes/supermemo2specialreview/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.scheduleId = data.supermemo2SpecialReview.scheduleId
                this.dataForm.specialId = data.supermemo2SpecialReview.specialId
                this.dataForm.currentEf = data.supermemo2SpecialReview.currentEf
                this.dataForm.currentQuantity = data.supermemo2SpecialReview.currentQuantity
                this.dataForm.islatest = data.supermemo2SpecialReview.islatest
                this.dataForm.interval = data.supermemo2SpecialReview.interval
                this.dataForm.createTime = data.supermemo2SpecialReview.createTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/avanotes/supermemo2specialreview/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'scheduleId': this.dataForm.scheduleId,
                'specialId': this.dataForm.specialId,
                'currentEf': this.dataForm.currentEf,
                'currentQuantity': this.dataForm.currentQuantity,
                'islatest': this.dataForm.islatest,
                'interval': this.dataForm.interval,
                'createTime': this.dataForm.createTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
